 /**
 * @author Richie
 * @constructor 
 */
StringUtils = function () {
	/**
	 * <b>判斷字串是否為空</b>
	 * @param 	checkStr 欲判斷之字串
	 * @return 	{boolean}
	 */
	this.isEmptyString = function (checkStr) {
		var result = true;
		if ((checkStr != null) && (checkStr != "")) {
			result = false;
		}
		return result;
	};

	/**
	 * <b>左補字串</b>
	 * @param 	origStr	原本字串
	 * @param 	length	指定長度
	 * @param 	newWord 補充字元
	 * @return 	{String}
	 */
	this.lPad = function (origStr, length, newWord) {
		var result = "";
		if (length > 0) {
			if (origStr.length < length) {
				var i = 0;
				
				while (result.length < (length - origStr.length)) {
					if (i >= newWord.length) {
						i = 0;
					}
					result += newWord.substring(i, 1);
					i++;
				}
			}
			result += origStr;
			return result;
		}else{
			return result;
		}
	};
	
	/**
	 * <b>右補字串</b>
	 * @param 	origStr	原本字串
	 * @param 	length	指定長度
	 * @param 	newWord 補充字元
	 * @return 	{String}
	 */
	this.rPad = function (origStr, length, newWord) {
		var result = "";
		if (length > 0) {
			if (origStr.length < length) {
				var i = 0;
				while (result.length < (length - origStr.length)) {
					if (i >= newWord.length) {
						i = 0;
					}
					result += newWord.substring(i, 1);
					i++;
				}
			}
			result = origStr + result;
			return result;
		}else{
			return result;
		}
	};

	/**
	 * <b>去除字串前後的空白</b>
	 * @param 	origStr	原本字串
	 * @Return	{String}
	 */
	this.trim = function (origStr){
		var result = "";
		result = origStr.replace(/[\s]*$/gi, "").replace(/^[\s]*/gi, "");
		return result;
	};

	/**
	 * <b>去除字串左邊的空白</b>
	 * @param 	origStr	原本字串
	 * @Return	{String}
	 */
	this.lTrim = function (origStr){
		var result = "";
		result = origStr.replace(/^[\s]*/gi, "");
		return result;
	};

	/**
	 * <b>去除字串右邊的空白</b>
	 * @param 	origStr	原本字串
	 * @Return	{String}
	 */
	this.rTrim = function (origStr){
		var result = "";
		result = origStr.replace(/[\s]*$/gi, "");
		return result;
	};
	
	/**
	 * <b>javascript replaceAll</b>
	 * @param	origStr	原先字串
	 * @param	target	指定目標
	 * @param	replacement 更換字串
	 * @return	{String}
	 */
	this.replaceAll = function (origStr, target, replacement){
		var index = 0;
		while (origStr.indexOf(target, index) != -1){
			origStr = origStr.replace(target, replacement);
			index = origStr.indexOf(target, index);
		}
		return origStr;
	};
	
	/**
	 * <b>javascript limitStr</b>
	 * @param	origStr	原先字串
	 * @param	length	限制長度
	 * @param	newWord 補充字元
	 * @return	{String}
	 */
	this.limitStr = function ( origStr, length, newWord ){
		origStr = origStr.substr( 0, length ) + newWord;
	    //document.write(str);
	    return origStr;
	};
};

var StringUtils = new StringUtils();